package com.eric.study.reactor.controller;

import com.eric.study.reactor.entity.ReactiveMessage;
import com.eric.study.reactor.service.ReactiveService;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api")
public class ReactiveController {

    @Resource
    private ReactiveService reactiveService;

    @GetMapping("/message")
    public Mono<String> getMessage() {
        return reactiveService.getMessage().map(str -> str + "!");
    }

    @PostMapping("/body")
    public Mono<ReactiveMessage> handleBody(@RequestBody ReactiveMessage message) {
        return reactiveService.handleBody(message);
    }
}